var e = getApp(), a = require("../../339469457B99569C55F201426D89DBD0.js"), t = require("../../38034BA77B99569C5E6523A090A9DBD0.js"), o = a.getImgCheckurl(), s = a.getFaceAgeUploadUrl(), i = a.getFaceAgeCoresUrl();

Page({
    data: {
        motto: "我们两个相似吗？",
        images: {},
        remark: "",
        score: "",
        scores: "",
        info: "",
        imgA: "",
        imgB: "",
        tempFilePathsA: "",
        tempFilePathsB: "",
        imgNameA: "",
        userInfo: {},
        backUserInfo: {},
        hasUserInfo: !1,
        openId: "",
        nickName: "",
        canIUse: wx.canIUse("button.open-type.getUserInfo"),
        imgNameB: "",
        token: null
    },
    onShareAppMessage: function() {
        return {
            title: "快来看我跟你有几分相似",
            path: "/pages/facedetectcrossageface/facedetectcrossageface",
            success: function(e) {
                "shareAppMessage:ok" == e.errMsg && wx.showToast({
                    title: "分享成功",
                    icon: "success",
                    duration: 500
                });
            },
            fail: function(e) {
                "shareAppMessage:fail cancel" == e.errMsg && wx.showToast({
                    title: "分享取消",
                    icon: "loading",
                    duration: 500
                });
            }
        };
    },
    bindViewTap: function() {
        wx.navigateTo({
            url: "../logs/logs"
        });
    },
    chooseImageA: function() {
        var e = this;
        wx.chooseImage({
            sourceType: [ "album", "camera" ],
            sizeType: [ "compressed" ],
            success: function(a) {
                console.log(a), a.tempFiles[0].size > 1048576 ? wx.showToast({
                    title: "图片文件过大哦",
                    image: "../../image/big.png",
                    mask: !0,
                    duration: 1500
                }) : (e.setData({
                    imgA: a.tempFilePaths[0],
                    tempFilePathsA: a.tempFilePaths,
                    score: "",
                    scores: "",
                    info: ""
                }), wx.uploadFile({
                    url: o,
                    filePath: a.tempFilePaths[0],
                    header: {
                        "content-type": "multipart/form-data"
                    },
                    name: "file",
                    formData: {
                        code: "XSYD"
                    },
                    success: function(a) {
                        var t = JSON.parse(a.data);
                        "0" == t.errcode ? wx.uploadFile({
                            url: s,
                            filePath: e.data.tempFilePathsA[0],
                            header: {
                                "content-type": "multipart/form-data"
                            },
                            name: "file",
                            success: function(a) {
                                var t = a.data;
                                console.info(a);
                                var o = JSON.parse(t);
                                e.setData({
                                    imgNameA: o.fileName,
                                    score: "",
                                    scores: "",
                                    info: ""
                                });
                            },
                            fail: function(e) {
                                wx.showModal({
                                    title: "上传失败",
                                    content: "服务器远走高飞了",
                                    showCancel: !1
                                });
                            }
                        }).onProgressUpdate(function(e) {
                            var a = e.progress;
                            100 == a ? (wx.hideToast(), wx.showToast({
                                title: "上传完成",
                                icon: "success",
                                mask: !0,
                                duration: 1500
                            })) : wx.showToast({
                                title: "正在上传" + a + "%",
                                icon: "loading",
                                mask: !0
                            });
                        }) : "87014" == t.errcode ? (wx.hideLoading(), wx.showModal({
                            content: "存在敏感内容，请更换图片",
                            showCancel: !1,
                            confirmText: "明白了"
                        }), e.setData({
                            imgA: null
                        })) : (wx.hideLoading(), wx.showModal({
                            content: "其他错误，稍后再试",
                            showCancel: !1,
                            confirmText: "明白了"
                        }));
                    }
                }));
            }
        });
    },
    chooseImageB: function() {
        var e = this;
        wx.chooseImage({
            sourceType: [ "album", "camera" ],
            sizeType: [ "compressed" ],
            success: function(a) {
                console.log(a), console.log(a.tempFiles[0].size), a.tempFiles[0].size > 1048576 ? wx.showToast({
                    title: "图片文件过大哦",
                    image: "../../image/big.png",
                    mask: !0,
                    duration: 1500
                }) : (e.setData({
                    imgB: a.tempFilePaths[0],
                    tempFilePathsB: a.tempFilePaths,
                    score: "",
                    scores: "",
                    info: ""
                }), wx.uploadFile({
                    url: o,
                    filePath: a.tempFilePaths[0],
                    header: {
                        "content-type": "multipart/form-data"
                    },
                    name: "file",
                    formData: {
                        code: "XSYD"
                    },
                    success: function(a) {
                        var t = JSON.parse(a.data);
                        "0" == t.errcode ? wx.uploadFile({
                            url: s,
                            filePath: e.data.tempFilePathsB[0],
                            header: {
                                "content-type": "multipart/form-data"
                            },
                            name: "file",
                            success: function(a) {
                                var t = a.data;
                                console.log(a);
                                var o = JSON.parse(t);
                                e.setData({
                                    imgNameB: o.fileName,
                                    score: "",
                                    scores: "",
                                    info: ""
                                }), wx.hideToast();
                            },
                            fail: function(e) {
                                wx.showModal({
                                    title: "上传失败",
                                    content: "服务器远走高飞了",
                                    showCancel: !1
                                });
                            }
                        }).onProgressUpdate(function(e) {
                            var a = e.progress;
                            100 == a ? (wx.hideToast(), wx.showToast({
                                title: "上传完成",
                                icon: "success",
                                mask: !0,
                                duration: 1500
                            })) : wx.showToast({
                                title: "正在上传" + a + "%",
                                icon: "loading",
                                mask: !0
                            });
                        }) : "87014" == t.errcode ? (wx.hideLoading(), wx.showModal({
                            content: "存在敏感内容，请更换图片",
                            showCancel: !1,
                            confirmText: "明白了"
                        }), e.setData({
                            imgB: null
                        })) : (wx.hideLoading(), wx.showModal({
                            content: "其他错误，稍后再试",
                            showCancel: !1,
                            confirmText: "明白了"
                        }));
                    }
                }));
            }
        });
    },
    onFaceAge: function(e) {
        var a = this;
        console.log(a), a.data.tempFilePathsA && a.data.tempFilePathsB ? (setTimeout(function() {
            wx.showToast({
                title: "结果马上就来...",
                icon: "loading",
                mask: !0
            });
        }, 500), wx.request({
            url: i,
            data: {
                imgNameA: a.data.imgNameA,
                imgNameB: a.data.imgNameB,
                openId: a.data.openId,
                nickName: a.data.nickName
            },
            success: function(e) {
                var t = e.data;
                0 == t.ret ? a.setData({
                    score: t.data.degree,
                    info: t.data.info,
                    scores: t.data.scores
                }) : 16402 == t.ret ? wx.showModal({
                    title: "温馨提示",
                    content: "图片中不包含人脸哦",
                    showCancel: !1
                }) : wx.showModal({
                    title: "温馨提示",
                    content: t.msg,
                    showCancel: !1
                }), wx.hideToast();
            },
            fail: function(e) {
                wx.hideToast(), console.log("============" + e.data);
            }
        })) : wx.showToast({
            title: "请选择图片哦",
            icon: "none",
            mask: !0,
            duration: 1e3
        });
    },
    chooseImage: function() {
        var e = this;
        wx.chooseImage({
            sourceType: [ "album", "camera" ],
            sizeType: [ "compressed" ],
            success: function(a) {
                console.log(a), a.tempFilePaths[0].size > 512e3 ? wx.showToast({
                    title: "图片文件过大哦",
                    icon: "none",
                    mask: !0,
                    duration: 1500
                }) : e.setData({
                    img: a.tempFilePaths[0],
                    tempFilePaths: a.tempFilePaths
                });
            }
        });
    },
    onLoad: function() {
        var a = this, o = e.data.openId;
        this.setData({
            openId: o
        }), t.tokenRequest({
            success: function(e) {
                a.setData({
                    token: e.access_token
                });
            }
        });
    }
});